package com.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author WaveHi
 * @Date 15/8/2021 上午 10:31
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description ArrayList的使用
 */
public class TestArrayList {

    public static void main(String[] args) {

        //获取ArrayList集合
        ArrayList<Person> persons = new ArrayList<>();

        //向集合添加数据
        persons.add(new Person("Tom", 23));
//        persons.add(10,new Person("Marry",123));

        //获取集合数据
        System.out.println("The data of index 0 in the collection is :" + persons.get(0));
        System.out.println("The data of index 3  in the collection is : " + persons.get(0));

        //修改集合数据
        persons.set(0, new Person("John", 12));

        //删除集合数据
        persons.remove(0);
        System.out.println("Completed!");

        //将集合转化为数组
        Person[] pers = new Person[10];
        Person[] people = persons.toArray(pers);
        System.out.println("The array \'people\' is " + Arrays.toString(people));

        //将数组转换为集合
        List<Person> people1 = Arrays.asList(people);
        System.out.println(people1);

    }

}
